package com.future.direction.ui.fragment;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.future.direction.R;
import com.future.direction.common.bus.BindEventBus;
import com.future.direction.common.bus.EventBusEvent;
import com.future.direction.common.bus.EventBusUtils;
import com.future.direction.data.bean.CourseCatalogueBean;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.adapter.CourseCatalogueAdapter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by xwl on 2019/11/12
 * 课程详情-目录
 */

public class CourseDetailsCatalogueFragment extends BaseFragment {

    @BindView(R.id.recycle_catalogue)
    RecyclerView recycleCatalogue;
    private ArrayList<CourseCatalogueBean> courseCatalogueBeans;
    private CourseCatalogueAdapter catalogueAdapter;

    @Override
    public int setLayout() {
        return R.layout.fragment_course_details_catalogue;
    }

    @Override
    protected void getExtras() {

    }

    @Override
    public void init() {
        initRecycler();
    }

    private void initRecycler() {
        courseCatalogueBeans = new ArrayList<>();
        CourseCatalogueBean courseCatalogueBean = new CourseCatalogueBean();
        courseCatalogueBean.setTitle("视频地址一");
        courseCatalogueBean.setStudy(false);
        courseCatalogueBean.setTime("20分钟");
        courseCatalogueBean.setUri("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
        courseCatalogueBeans.add(courseCatalogueBean);
        CourseCatalogueBean courseCatalogueBean1 = new CourseCatalogueBean();
        courseCatalogueBean1.setTitle("视频地址二");
        courseCatalogueBean1.setStudy(false);
        courseCatalogueBean1.setTime("20分钟");
        courseCatalogueBean1.setUri("http://vjs.zencdn.net/v/oceans.mp4");
        courseCatalogueBeans.add(courseCatalogueBean1);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        recycleCatalogue.setLayoutManager(manager);
        catalogueAdapter = new CourseCatalogueAdapter(R.layout.item_course_catalogue, courseCatalogueBeans);
        recycleCatalogue.setAdapter(catalogueAdapter);
    }

    @Override
    protected void setListener() {
        catalogueAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                catalogueAdapter.setSelectPosition(position);
                CourseCatalogueBean courseCatalogueBean = catalogueAdapter.getData().get(position);
                EventBusUtils.sendEvent(new EventBusEvent<CourseCatalogueBean>(EventBusUtils.EventCode.VIDEO_AUDIO_URL, courseCatalogueBean));
            }
        });
    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }


}
